﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OneSys.Misc
{
    public partial class FrmSN : DevExpress.XtraEditors.XtraForm
    {
        public FrmSN()
        {
            InitializeComponent();
            this.memoEditHW.Text = MachineCode.GetMachineCode();
        }

        private void btnCopy_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(memoEditHW.Text);
        }


        private void btnRegist_Click(object sender, EventArgs e)
        {

            if (String.IsNullOrEmpty(memoEditSN.Text))
            {

                XtraMessageBox.Show(resource.GetString("WarningText"), "",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            var fullName = Assembly.GetEntryAssembly().Location;

            using (var sr = new StreamWriter(Path.GetFileNameWithoutExtension(fullName) + ".lic"))
            {
                sr.Write(memoEditSN.Text);
            }
            Close();
            DialogResult = DialogResult.OK;
        }

        private void FrmSN_Load(object sender, EventArgs e)
        {
            resource = new System.ComponentModel.ComponentResourceManager(typeof(FrmSN));
        }
        private System.ComponentModel.ComponentResourceManager resource;

    }
}
